
local assert     = assert
local require    = require    
local bit        = bit
local coroutine  = coroutine
local debug      = debug
local io         = io
local pairs      = pairs
local ipairs     = ipairs
local math       = math
local os         = os
local print      = print
local pcall      = pcall
local xpcall     = xpcall
local rawget     = rawget
local rawset     = rawset
local select     = select
local string     = string
local table      = table
local tonumber   = tonumber
local tostring	 = tostring
local error      = error
local type       = type
local unpack     = unpack
local setmetatable = setmetatable
local getmetatable = getmetatable
local ngx = ngx
local string_find = string.find
local string_sub  = string.sub

----数据变量----
local uu         = require("modules.commhm.utils");
local log        = require("modules.commhm.log");
local ns_time    = require("modules.commhm.time");
local ns_auth_comm_checker = require("modules.commhm.auth_comm_checker")

local Log = log.debug;

local FOO = {
	_VERSION = '0.12.1',
};

-------------------------------------S7
FOO.ns_http_sec = ns_auth_comm_checker.ns_http_sec


--设置数据库auth
FOO.get_data_cache_auth = function()
	return true
end


--检查数据库auth 使用弱加密
FOO.check_data_cache_auth = function( cmd_ )
	if  "Xcn67K" == ngx.ctx.m_params.auth then
		---内网固定密码
		return 1
	else
		---外网请求加密
		if  ngx.ctx.m_params.time and cmd_ then
			local auth_ = ns_auth_comm_checker.gen_comm_inner_token( ngx.ctx.m_params.uin, ngx.ctx.m_params.time, cmd_ )
			if  auth_ == ngx.ctx.m_params.auth then
				return 2
			end
		end
	end
	return false
end


---- 校验加密
FOO.check_data_cache_khv_auth = function( args_ )
	if  args_.auth_dc then
		local auth_dc_cal_ = ns_auth_comm_checker.gen_data_cache_auth( args_.name, args_ )
		if  args_.auth_dc == auth_dc_cal_ then
			log.debug( "auth_dc_cal_check_ok" )
			return 0
		else
			log.error( "auth_dc_cal_check_fail1" )
		end
	else
		log.error( "auth_dc_cal_check_fail2" )
	end
	return 1
end



return FOO;
